home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / audacity / plug-ins / equalabel.ny < prev    next >
Encoding:
Audacity Nyquits plug-in  |  2010-09-21  |  5.0 KB  |  143 lines

  1. ;nyquist plug-in
  2. ;version 3
  3. ;type analyze
  4. ;categories "http://audacityteam.org/namespace#TimeAnalyser"
  5. ;name "Regular Interval Labels..."
  6. ;action "Adding equally-spaced labels to the label track..."
  7. ;info "equalabel.ny by David R. Sky www.shellworld.net/~davidsky/ \nReleased under terms of the GNU General Public License version 2\nCreate equally spaced labels by choosing the number of labels or the interval\nbetween them. Making your final audio segment equal with others may slightly\nchange the label interval that you had set.\nNote: Equalabel.ny does not overwrite an existing label track, but adds to it.\nCode for label placement based on silencemarker.ny by Alex S.Brown."
  8.  
  9. ;control start "Time to place first label [seconds]" string " " "0.0"
  10. ;control placement "Label placement method" choice "Label interval,Number of labels" 0
  11. ;control time "Set either: Label interval [seconds]" string " " "60.0"
  12. ;control label-number "Or: Number of labels" int "" 10 2 100
  13. ;control text "Label text" string "" "Label"
  14. ;control prepend "Prepend numbers to label text?" choice "No - just use text,Yes" 1
  15. ;control include "Include final label?" choice "No,Yes" 0
  16. ;control t-choice "Final audio segment equal with others?" choice "No,Yes" 1
  17.  
  18. ; Regular interval labels by David R. Sky, June-October 2007.
  19. ; Released under terms of the GNU General Public License version 2
  20. ; http://www.gnu.org/copyleft/gpl.html
  21. ; Thanks Sami Jumppanen for plug-in suggestion.
  22. ; Thanks Alex S. Brown for code showing how to place labels.
  23. ; Thanks Dominic Mazzoni, Pierre M.I., Gale Andrews 
  24. ; for improvement suggestions.
  25.  
  26.  
  27. ; function to convert string to list
  28. (defun string-to-list (str)
  29. (read (make-string-input-stream (format nil "(~a)" str))))
  30.  
  31.  
  32. ; convert start string to a number
  33. (setf start (first (string-to-list start)))
  34.  
  35. ; convert time string to a number
  36. (setf time (first (string-to-list time)))
  37.  
  38. ; get selection duration in seconds,
  39. ; then subtract start offset
  40. (setf dur (- (/ len *sound-srate*) start))
  41.  
  42. ; give an error message 
  43. ; if user-set label interval is greater than selection duration,
  44. ; taking into accound start time offset
  45. (cond ; outermost cond
  46. ((and (> time dur) (= placement 0))
  47. (format nil
  48. "Including your time offset of ~a seconds, your requested~%label interval of ~a seconds is greater than the duration~%of your selected audio (~a seconds). ~%
  49. Please run this plug-in again using a smaller label interval. ~%" 
  50. start time dur))
  51.  
  52. (t ; label interval time is equal to or less than selection duration
  53.  
  54. ; choose between user-selected label interval or number of labels
  55. (cond 
  56. ((= placement 1) ; number of labels
  57. (setf time (if (= include 0)
  58. (float (/ dur label-number)) (1+ (float (/ dur label-number)))))
  59. (setf labels (if (= include 0) label-number (1+ label-number)))
  60. ) ; end placement 1
  61.  
  62. (t ; user-selected time interval
  63. ; calculate number of labels in selection
  64. ; this includes label at start of selection
  65. ; which is label number 0 if numbers are prepended to label text
  66. ; if final label is unwanted, decrement number of labels by 1
  67. (setf labels  (if (= include 0)
  68. (truncate (/ dur time))
  69. (+ 1 (truncate (/ dur time)))
  70. ) ; end if
  71. ) ; end setf labels
  72.  
  73. ; setf check-labels: number of labels if user includes last label
  74. ; this is for checking purposes in the [setf time ...] section of code
  75. (setf check-labels (+ 1 (truncate (/ dur time))))
  76.  
  77.  
  78. ; function to calculate new time value 
  79. ; if user value does not create equal duration final audio chunk
  80. ; returns new time value
  81. (defun new-time (time dur check-labels)
  82. ; calculate duration of last audio chunk
  83. (setf last-label (- dur (* time check-labels)))
  84. (if (< last-label (* time 0.5)) ; last chunk is less than 1/2 time
  85. (/ dur (- check-labels 1))
  86. (/ dur check-labels)
  87. ) ; end if
  88. ) ; end defun new-time
  89.  
  90.  
  91. (setf time ; depending whether user wants specified time used 
  92. ; or wants equal duration audio chunks including last chunk
  93. ; user time may create equal audio chunks even for last chunk
  94. (cond ; 1
  95. ((= t-choice 0) time) ; use user time value...
  96.  
  97. (t ; ...otherwise calculate time for equal duration audio chunks
  98. (cond ; 2 
  99. ; if user time value creates equal final audio segment duration anyway 
  100. ; then use user interval
  101. ((= dur (* time (- check-labels 1))) time)
  102.  
  103. ; user time value does not create equal duration audio chunks
  104. (t 
  105. (new-time time dur check-labels)
  106. ) ; end t
  107. ) ; end cond 2
  108. ) ; end of calculation for equal duration audio chunks
  109. ) ; end cond1
  110. ) ; end setf time
  111.  
  112. ) ; end t
  113. ) ; end cond choosing between user-set label interval or number of labels
  114.  
  115.  
  116. ; function to add labels to the label track
  117. ; from silencemarker.ny by Alex S. Brown
  118. (defun add-label (l-time l-text)
  119.  (setq l (cons (list l-time l-text) l)))
  120.  
  121.  
  122. ; function to prepend label number before label text
  123. (defun prepend-number (i text)
  124. (format nil "~a~a" i text))
  125.  
  126.  
  127. ; initialize blank label track
  128. (setq l nil)
  129.  
  130. ; add the labels
  131. (dotimes (i labels)
  132. (if (= prepend 1) ; prepend numbers to label text?
  133. (add-label (+ start (* i time)) (prepend-number i text)) ; yes
  134. (add-label (+ start (* i time)) text) ; no
  135. ) ; end if
  136. ) ; end dotimes i
  137.  
  138. ; return label track
  139. l
  140.  
  141. ) ; close t of outermost cond
  142. ) ; end outermost cond
  143.